import { SearchParamsProps } from "@/components/s-table/type";
import { t } from "@/locales";
import { FormRule, Icon, PrimaryTableCol, SelectProps, Tag } from "tdesign-vue-next";

/**
 * 搜索表单项
 */
export const searchParams: SearchParamsProps[] = [
    {
        label: t('pages.sysPermission.name'),
        key: 'name',
    },
    {
        label: t('pages.sysPermission.englishName'),
        key: 'englishName',
    },
    {
        label:'',
        key: 'type',
        hide: true,
        defaultValue: 0,
    },
    {
        label:'',
        key: 'tree',
        hide: true,
        defaultValue: true,
    },
];

/**
 * 表格列
 */
export const COLUMNS: PrimaryTableCol[] = [
        //配置表格前面勾选项
    {   colKey: 'row-select', 
        type: 'multiple', 
        width: 50,
    
    },
    {
        title: t('pages.sysPermission.name'),
        ellipsis: true,
        align: 'center',
        colKey: 'name',
    },
    {
        title: t('pages.sysPermission.path'),
        align: 'center',
        colKey: 'path',
    },
    {
        title: t('pages.sysPermission.englishName'),
        ellipsis: true,
        align: 'center',
        colKey: 'englishName',
    },
    {
        title: t('pages.sysPermission.code'),
        ellipsis: true,
        align: 'center',
        colKey: 'code',
    },
    {
        title: t('pages.sysPermission.outerChain'),
        ellipsis: true,
        align: 'center',
        colKey: 'outerChain',
        cell:(h, {row}) => h(Tag,
            {theme:'danger',
             variant:'light',
          
            },t(`components.YesNo.${row.outerChain == 0 ? 'No' : 'Yes'}`))
    },
    {
        title: t('pages.sysPermission.icon'),
        ellipsis: true,
        align: 'center',
        colKey: 'icon',
        cell: (h, { row }) => h(Icon,
            {
                name: row.icon,
            },
        ),
    },
    {
        title: t('pages.sysPermission.sort'),
        ellipsis: true,
        align: 'center',
        colKey: 'sort',
    },
    {
        title: t('pages.sysPermission.remarks'),
        ellipsis: true,
        align: 'center',
        colKey: 'remarks',
    },
];

/**
 * 表单校验规则
 */
export const FORM_RULES: Record<string, FormRule[]> = {
    type: [{required: true, message: t('pages.sysPermission.required.type'), type: 'error', trigger: 'all'}],
    parentId: [{required: true, message: t('pages.sysPermission.required.parentId'), type: 'error', trigger: 'change'}],
    name: [{required: true, message: t('pages.sysPermission.required.name'), type: 'error', trigger: 'blur'}],
    englishName: [{required: true, message: t('pages.sysPermission.required.englishName'), type: 'error', trigger: 'blur'}],
    path: [{required: true, message: t('pages.sysPermission.required.path'), type: 'error', trigger: 'blur'}],
    sort: [{required: true, message: t('pages.sysPermission.required.sort'), type: 'error', trigger: 'blur'}],
}

/**
 * 配置类型下拉选项（type）
 */
export const typeOption: SelectProps['options'] = [
    {
        label: t('pages.sysPermission.typeOption.parent'),
        value: 0
    },
    {
        label: t('pages.sysPermission.typeOption.children'),
        value: 1
    },
    {
        label: t('pages.sysPermission.typeOption.perms'),
        value: 2
    }
]
/**
 * 配置类型是否外链选项（type）
 */
export const outerChainOption: SelectProps['options'] = [
    {
        label: t('components.YesNo.Yes'),
        value: 1
    },
    {
        label: t('components.YesNo.No'),
        value: 0
    }

]